#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/11/13 17:06
    Desc  :
--------------------------------------
"""
from time import time

from flask import jsonify


class JsonResponse():

    def __init__(self, code:int, data: any, message= "请求成功", errors = None):

        self.code = code
        self.data = None if data is None else data
        self.message = None if message is None else message
        self.errors = None if errors is None else errors

    def jsonExit(self):

        result = {
            "code": self.code,
            "message": self.message,
            "data": self.data,
            "errors": self.errors,
            "systemTime": int(time() * 1000)
        }

        if self.errors is None:
            del result['errors']

        return jsonify(result)

